
AddCSLuaFile( "cl_init.lua" ) //dl that
AddCSLuaFile( "shared.lua" ) //dl that too
AddCSLuaFile( "specialchars.lua" ) //and this
AddCSLuaFile( "cl_hud.lua" )

resource.AddFile("data/CG_FUN")


AddCSLuaFile( "resouces.lua" )


include( "resources.lua" )
include( 'shared.lua' ) //load that
include( 'specialchars.lua' ) //This too.
include( "exp_data.lua" )
include( "exp_powerups.lua" )
include( "trail.lua" )


function GM:PlayerSpawn( ply )
    self.BaseClass:PlayerSpawn( ply )
    ply:SetGravity( 0.75 )
    ply:SetMaxHealth( 100, true )

    ply:SetWalkSpeed( 325 )
	ply:SetRunSpeed( 325 )

end


function SchoolShow( ply )
	umsg.Start("open_shoppanel", ply)
	umsg.End()
end
hook.Add("ShowSpare1", "help", SchoolShow)



function playerSaid( ply, saywhat )
	if string.find(saywhat, "!Help") == 1 then
		umsg.Start("help", ply)
		umsg.End()
	end
end

hook.Add ( "PlayerSay", "playerSaid", playerSaid )


function GM:Initialize()
	game.ConsoleCommand("sbox_godmode 1")
	addadminmodels()
end



function GM:PlayerHurt( player, attacker )
	return false
end



function GM:PlayerInitialSpawn( ply )
	CheckSpecialCharacters( ply )
	if ply:IsAdmin() then
		sb_team2( ply )
	else
	joining( ply )
	end

	umsg.Start("open_motd", ply)
	umsg.End()

end //close the function



local function DisableNoclip( objPl )
	return objPl:IsAdmin() -- don't need IsSuperAdmin because IsSuperAdmin counts in IsAdmin
end
hook.Add("PlayerNoClip", "DisableNoclip", DisableNoclip)



function FirstSpawn( ply )

	ply:PrintMessage(HUD_PRINTTALK,"[Lobby] Welcome to the server!")

end

hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )


function GM:PlayerLoadout( ply )

	if ply:Team() == 1 then
		ply:Give( "weapon_physcannon" )
		ply:Give( "weapon_physgun" )


	elseif ply:Team() == 2 then // So if he isn't team 1, he could be team 2?

		ply:Give( "weapon_physcannon" ) //Assuming he is, then give him Gravity gun
		ply:Give( "weapon_physgun" ) // Physics gun
		ply:Give( "weapon_ar2" ) // AR2

	//I should mention at this point you can put in else, but there is no point. All possible scenarios are covered. Thus we end it
	end //right here.
end // End the function

// teams -------------------------------

function sb_team1( ply ) //This is what happens when we enter sb_team1 into the console.

	ply:UnSpectate() //Since he was set to spectate until he presses the 'hell yeah' button, we now unspecatate him
	ply:SetTeam( 1 ) //We set his team to one, a.k.a 'guest'
	ply:Spawn() //Spawn the player
	ply:PrintMessage( HUD_PRINTTALK, "[Lobby] Welcome to the server, " .. ply:Nick() ) //Gives the message [SimpleBuild]Welcome to the server, (playername here)"  in the talk area.

end //End the function.


function sb_team2( ply ) // Function sb_team2. Called at the beginning
	// Why no unspectate? Look carefully at the GM:PlayerSpawn; We only call to spectate after we see if he's an admin. Assuming he's always ready to build, I chose to skip it.
	ply:SetTeam( 2 ) //Set his team to team 2.
	ply:Spawn() // Spawn him
	ply:PrintMessage( HUD_PRINTTALK, "[Lobby] Loading your admin priviledges, " .. ply:Nick() )
	ply:PrintMessage( HUD_PRINTTALK, "[Lobby] Loaded your admin priviledges, " .. ply:Nick() )

end //End this function
concommand.Add( "sb_team1", sb_team1 ) //Now, we make sure that when we enter sb_team1 into console that it calls the function. This is KEY. Otherwise players won't be able to play.

function joining( ply ) // The function that's called when the player is not admin or a special character, at the top.

	ply:Spectate( 5 ) //Set him to spectate in free-roam mode. He doesn't actually fly around, since he has a window open at this point.
	ply:SetTeam( 1 ) //Set his team to Joining

end //End the function

// i dont want suicidal players

function GM:CanPlayerSuicide( ply )
	if ply:IsAdmin() then
		ply:PrintMessage(HUD_PRINTTALK, "You commited suicide!")
		return true
	end
	ply:PrintMessage(HUD_PRINTTALK, "You can't suicide!")
	return false
end

function GM:OnPlayerHitGround( pl )
	if pl:IsAdmin() then
		local boom = ents.Create( "env_explosion" )
		boom:SetPos( pl:GetPos( ) )
		boom:Spawn( )
		boom:Fire( "explode", "", 0 )
		for _, pl in pairs(player.GetAll()) do
			pl:ConCommand("r_cleardecals")
		end
	end
end


function iWantMySuitBack(ply, cmd, args)
	if args[1]:IsPlayer() then
		args[1]:EquipSuit()
	end
end

concommand.Add("givehev", iWantMySuitBack)
